package com.zhangdy.agent.config;


import com.zhangdy.agent.exception.AgentException;
import com.zhangdy.agent.resp.AgentResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class AgentThrowableHandler {
    private static Logger logger = LoggerFactory.getLogger(AgentThrowableHandler.class);

    @ExceptionHandler(value = AgentException.class)
    public AgentResponse agentException(AgentException e){
        logger.error("【业务异常】", e);
        return AgentResponse.fail(e.getMessage());
    }


    @ExceptionHandler(value =Throwable.class)
    public AgentResponse throwable(Throwable e){
        logger.error("【未知异常】", e);
        return AgentResponse.FAIL;
    }





}
